package com.gp.node;

import com.stock.StockData;
import com.utils.CONST;
import com.utils.Random;

// this class represent IValue nodes that contains avg price in their value 
// override functions description can be found at the interface IValue
public class AvgPrice extends IValue {

	private static final long serialVersionUID = 6092192070176420432L;
	// the avg price
	int avg = 0;
	
	// c'tor - set random value
	public AvgPrice() {
		avg = CONST.avgNumDays[Random.nextInt(CONST.avgNumDays.length)];
	}
	
	// c'tor - set given value
	public AvgPrice(int avg) {
		this.avg = avg;
	}
	
	@Override
	public double getValue(StockData stock) {
		return stock.getAvg(avg);
	}
	
	@Override
	public INode createNew()  {
		return new AvgPrice();
	}

	@Override
	public INode copy() {
		return  new AvgPrice(avg);
	}
	
	@Override
	public String print(StockData stock) {
		return String.valueOf(stock.getAvg(avg));
	}
	
	@Override
	public String print() {
		return " AvgPrice_"+avg+" ";
	}
	
}
